package Model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

/**
 * non playable character class
 *
 */
public class NPC implements I_Interactable, Serializable{
	/**
	 * damage of npc
	 */
	private final int damage;

	/**
	 * defense of npc
	 */
	private final int defense;

	/**
	 * health of npc
	 */
	private final int health;

	/**
	 * type of npc
	 */
	private final NPCType type;

	/**
	 * fighter of npc
	 */
	private Fighter fighter;
	
	/**
	 * @return list of all npctypes
	 */
	public static List<NPCType> npcTypeList(){
		final List<NPCType> list = new LinkedList<NPCType>();
		list.add(NPC.NPCType.PIRATE);
		list.add(NPC.NPCType.POLICE);
		list.add(NPC.NPCType.TRADER);
		
		return list;
	}
	
	/**
	 * 
	 *Enum Class that contains all npc types 
	 */
	public enum NPCType
	{
		POLICE("Police", 10, 25, 100), PIRATE("Pirate", 15, 10, 100), 
		    TRADER("Trader", 0, 0, 100);
		
		/**
		 * name of npc type
		 */
		private final String name;

		/**
		 * npc of npc type
		 */
		private final NPC npc;
		
		/**
		 * Constructor
		 * 
		 * @param name
		 * @param damage
		 * @param defense
		 * @param health
		 */
		private NPCType(String name, int damage, int defense, int health){
			this.name = name;
			this.npc = new NPC(this, damage, defense, health);
		}
		
		/**
		 * getter for name
		 * @return name
		 */
		public String getName(){
			return name;
		}
		
		/**
		 * getter for npc
		 * @return npc
		 */
		public NPC getNPC(){
			return npc;
		}
	}
	
	/**
	 * Constructor for NPC
	 * 
	 * @param type
	 * @param damage
	 * @param defense
	 * @param health
	 */
	private NPC(NPCType type, int damage, int defense, int health){
		this.damage = damage;
		this.defense = defense;
		this.health = health;
		this.type = type;
		createFighter();
	}

	/* (non-Javadoc)
	 * @see Model.I_Interactable#actionList()
	 */
	@Override
	public List<Actions> actionList() {
		final List<Actions> list = new LinkedList<Actions>();
		
		if(type == NPCType.PIRATE){
			list.add(Actions.ATTACK);
			list.add(Actions.SURRENDER);
			list.add(Actions.FLEE);
		}
		else if(type == NPCType.POLICE){
			list.add(Actions.ATTACK);
			list.add(Actions.IGNORE);
			list.add(Actions.BRIBE);
		}
		else{
			list.add(Actions.DONOTTRADE);
			list.add(Actions.TRADE);
		}
		
		return list;
	}
	
	/**
	 * getter for npc type
	 * @return type
	 */
	public NPCType getType(){
		return type;
	}
	
	/**
	 * creates a new fighter using the damage, defense, and health fields of npc
	 */
	private void createFighter(){
		fighter = new Fighter(damage, defense, health);
	}
	
	/**
	 * attack action
	 * @return the fast attack value of the fighter
	 */
	public int attack(){
		return fighter.fastAttack();
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString(){
		return super.toString();
	}
}
